package com.itheima.config;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;

import javax.servlet.Filter;

//把springmvcconfig 生成容器 把容器加载到tomcat容器
//配置拦截路径 - 找到指定的controller映射路径
public class ServletlnitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    //其他资源配置
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }
    //参与映射的资源配置
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }
    //拦截的映射路径
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    //接收post参数乱码
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter f = new CharacterEncodingFilter();
        f.setEncoding("utf-8");
        return new Filter[]{f};
    }
}


/*
    public class ServletlnitConfig extends AbstractDispatcherServletInitializer {

    //把springmvcconfig 生成容器 把容器加载到tomcat容器
    @Override
    protected WebApplicationContext createServletApplicationContext() {
        AnnotationConfigWebApplicationContext app = new AnnotationConfigWebApplicationContext();
        app.register(SpringMvcConfig.class);
        return app;
    }
    //配置拦截路径 - 找到指定的controller映射路径

    @Override
    protected String[] getServletMappings() {
        //拦截路径
        return new String[]{"/"};
    }

    @Override
    protected WebApplicationContext createRootApplicationContext() {
        return null;
    }
}
*/